/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Enquiry;

import Category.CategoryBean;
import Course.CourseBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mishra
 */
public class EnquirySearchByName extends HttpServlet {

   
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String sName=request.getParameter("name");
           Vector<Object> list=Enquiry.Query.SearchByName(sName);
           if(!list.isEmpty())
           {
               Iterator it=list.iterator();
               while(it.hasNext())
               {
                  EnquiryBean eb=(EnquiryBean)it.next();
                  CourseBean cb=eb.getCourseBean();
                  CategoryBean cab=eb.getCategoryBean();
                  out.println("<tr id='"+eb.getEnquiryId()+"'>");
                  String gen="";
                  if(eb.getGender().equals("1"))
                  {
                      gen="Male";
                  }
                  else
                  {
                      gen="Female";
                  }
                  out.println("<td>");
                  out.println("<b>Name:</b>&nbsp"+eb.getStudentName()+"<br><b>Gender:</b>&nbsp"+gen+"<br><b>DOB:</b>&nbsp"+eb.getDob()+"<br><b>Father Name:</b>&nbsp"+eb.getFatherName());
                  out.println("</td>");
                  out.println("<td>");
                  out.println("<b>Mobile No.:</b>&nbsp"+eb.getMobileNo()+"<br><b>Email ID:</b>&nbsp"+eb.getEmail()+"<br><b>Category:</b>&nbsp"+cab.getCategory());
                  out.println("</td>");
                  String pros="";
                  if(eb.getProspectus()==1){
                      pros="Issued";
                  }
                  else{
                   pros="Not Issued";
                  }
                  out.println("<td>");
                  out.println("<b>Course:</b>&nbsp"+cb.getCourseName()+"<br><b>Stream:</b>&nbsp"+eb.getStream()+"<br><b>Prospectus:</b>&nbsp"+pros);
                  out.println("</td>");
                  out.println("<td>");
                  out.println("<b>Date of Enquiery:</b>&nbsp"+eb.getEntryDate()+"<br><b>Date of Addmission:</b>&nbsp"+eb.getDor());
                  out.println("</td>");
                  out.println("<td>");
                  out.println("<b>Exam:</b>&nbsp"+eb.getEntranceExName()+"<br><b>Mark:</b>&nbsp"+eb.getMarks()+"<br><b>Rank:</b>&nbsp"+eb.getRank()+"<br><b>Exam:</b>&nbsp"+eb.getoEntranceExName()+"<br><b>Mark:</b>&nbsp"+eb.getoMarks()+"<br><b>Rank:</b>&nbsp"+eb.getoRank());
                  out.println("</td>");
                  
                  String doBirth="", doReg="";
                  String doreg[]={};
                  String dateb="", dater="";
                   
                   doBirth = eb.getDob().toString();
                   String dob1[] = doBirth.split("-");
                   dateb= dob1[1]+"/"+dob1[2]+"/"+dob1[0];
                   
                   doReg = eb.getDor().toString(); 
                   doreg = doReg.split("-");
                   dater = doreg[1]+"/"+doreg[2]+"/"+doreg[0];
                  
                  out.println("<td style='text-align:center;'>");
                  out.println("<a href='EditEnquiry.jsp?eid="+eb.getEnquiryId()+"&sname="+eb.getStudentName()+"&dob="+dateb+"&dor="+dater+"&gender="+eb.getGender()+"&fname="+eb.getFatherName()+"&fmobile="+eb.getMobileNo()+"&email="+eb.getEmail()+"&courseid="+eb.getCourseId()+"&coursename="+cb.getCourseName()+"&stream="+eb.getStream()+"&prospe="+eb.getProspectus()+"&entrydate="+eb.getEntryDate()+"&entryemail="+eb.getEntryEmail()+"&enexamname="+eb.getEntranceExName()+"&exmark="+eb.getMarks()+"&exrank="+eb.getRank()+"&oentexname="+eb.getoEntranceExName()+"&oexmark="+eb.getoMarks()+"&oexrank="+eb.getoRank()+"&catid="+eb.getCategoryId()+"&catename="+cab.getCategory()+"'><button class='btn btn-info' style='min-width: 67px;'>Edit</button></a>");
                  out.println("<br><br><a href='#'><button class='btn btn-danger' onclick='deleteEnquiryConfirm("+eb.getEnquiryId()+")'>Delete</button></a>");
                  out.println("</td>");
                  out.println("</tr>");
               }
           }
           else
           {
               out.println("<tr>");
               out.println("<td colspan='3'>");
               out.println("<b>No Record Found</b>");
               out.println("</td>");
               out.println("</tr>");
           }
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(EnquirySearchByName.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(EnquirySearchByName.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
